﻿using System.ComponentModel;
using Loki.Utils;
using Luna.Model.CRM;

namespace Luna.UI.Contacts
{
    public class DisplayableAccount : LunaDisplayable
    {
        #region Name

        private static PropertyChangedEventArgs _NameChangedArgs = ObservableHelper.CreateChangedArgs<DisplayableAccount>(x => x.Name);

        private static PropertyChangingEventArgs _NameChangingArgs = ObservableHelper.CreateChangingArgs<DisplayableAccount>(x => x.Name);

        private string _Name;

        public string Name
        {
            get
            {
                return _Name;
            }

            set
            {
                if (value != _Name)
                {
                    NotifyChanging(_NameChangingArgs);
                    _Name = value;
                    NotifyChanged(_NameChangedArgs);
                }
            }
        }

        #endregion Name

        #region Address

        private static PropertyChangedEventArgs _AddressChangedArgs = ObservableHelper.CreateChangedArgs<DisplayableAccount>(x => x.Address);

        private static PropertyChangingEventArgs _AddressChangingArgs = ObservableHelper.CreateChangingArgs<DisplayableAccount>(x => x.Address);

        private string _Address;

        public string Address
        {
            get
            {
                return _Address;
            }

            set
            {
                if (value != _Address)
                {
                    NotifyChanging(_AddressChangingArgs);
                    _Address = value;
                    NotifyChanged(_AddressChangedArgs);
                }
            }
        }

        #endregion Address

        #region Mail

        private static PropertyChangedEventArgs _MailChangedArgs = ObservableHelper.CreateChangedArgs<DisplayableAccount>(x => x.Mail);

        private static PropertyChangingEventArgs _MailChangingArgs = ObservableHelper.CreateChangingArgs<DisplayableAccount>(x => x.Mail);

        private string _Mail;

        public string Mail
        {
            get
            {
                return _Mail;
            }

            set
            {
                if (value != _Mail)
                {
                    NotifyChanging(_MailChangingArgs);
                    _Mail = value;
                    NotifyChanged(_MailChangedArgs);
                }
            }
        }

        #endregion Mail

        #region PhoneNumber

        private static PropertyChangedEventArgs _PhoneNumberChangedArgs = ObservableHelper.CreateChangedArgs<DisplayableAccount>(x => x.PhoneNumber);

        private static PropertyChangingEventArgs _PhoneNumberChangingArgs = ObservableHelper.CreateChangingArgs<DisplayableAccount>(x => x.PhoneNumber);

        private string _PhoneNumber;

        public string PhoneNumber
        {
            get
            {
                return _PhoneNumber;
            }

            set
            {
                if (value != _PhoneNumber)
                {
                    NotifyChanging(_PhoneNumberChangingArgs);
                    _PhoneNumber = value;
                    NotifyChanged(_PhoneNumberChangedArgs);
                }
            }
        }

        #endregion PhoneNumber

        public IAccount Account
        {
            get
            {
                return ApplicationModel.CRM.Accounts[ID];
            }
        }

        public void LoadFrom(IAccount P_Account)
        {
            BeginInit();
            ID = P_Account.ID;
            Name = P_Account.Name;
            Address = P_Account.Address;
            EndInit();
        }
    }
}